package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.domain.business.BusinessDO;
import com.qk.entity.Business;
import com.qk.entity.dto.business.BusinessDTO;
import com.qk.entity.dto.business.BusinessListDTO;
import com.qk.entity.dto.business.BusinessPoolDTO;
import com.qk.entity.dto.business.UpdateBusinessInfoDTO;
import com.qk.entity.vo.business.BusinessVO;
import com.qk.management.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author fantuan
 * @created 2025/10/15 10:55
 * @description
 */
@RestController
@RequestMapping("/businesses")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    @PostMapping("/toCustomer/{id}")
    public Result toCustomer(@PathVariable Integer id){
        businessService.toCustomerById(id);
        return Result.success();
    }

    @GetMapping("/pool")
    public Result pool(BusinessPoolDTO dto){
        PageResult<Business> vo = businessService.selectBusinessPool(dto);
        return Result.success(vo);
    }

    @PutMapping("/back/{id}")
    public Result back(@PathVariable Integer id){
        businessService.backBusinessById(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectBusinessById(@PathVariable Integer id){
        BusinessVO business = businessService.selectBusinessById(id);
        return Result.success(business);
    }

    @PutMapping
    public Result updateBusiness(@RequestBody UpdateBusinessInfoDTO dto){
        businessService.updateBusinessInfo(dto);
        return Result.success();
    }

    @PutMapping("/assign/{businessId}/{userId}")
    public Result updateBusinessById(@PathVariable Integer businessId, @PathVariable Integer userId){
        businessService.updateBusinessById(businessId,userId);
        return Result.success();
    }

    @PostMapping
    public Result addBusiness(@RequestBody BusinessDTO dto) {
        businessService.addBusiness(dto);
        return Result.success();
    }

    @GetMapping
    public Result BusinessList(BusinessListDTO dto){
        PageResult<BusinessDO> result =  businessService.selectBusinessList(dto);
        return Result.success(result);
    }
}
